package com.bawei.live.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bawei.live.databinding.ItemGlobalFlashLayoutBinding

import com.bawei.live.entity.UserEntity

/**
 * @author: 王奎
 * @date: 2025/2/17
 */
class GloBalFlashTypeAdapter constructor(private val list:MutableList<UserEntity>):
RecyclerView.Adapter<GloBalFlashTypeAdapter.ItemViewHolder>(){


    private var itemClickListener:OnItemClickListener? = null

    interface OnItemClickListener{
        fun onItemClick(v: View, positions:Int)
    }
    fun setOnItemClickListener(listener:OnItemClickListener){
        itemClickListener = listener
    }
    inner class ItemViewHolder(val dataBinding2: ItemGlobalFlashLayoutBinding):
        RecyclerView.ViewHolder(dataBinding2.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        var itemDataBinding = ItemGlobalFlashLayoutBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return ItemViewHolder(itemDataBinding)
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        val entity = list[position]

        //设置排名
        holder.dataBinding2.tvNumber.text = entity.textCount.toString()
        //设置用户昵称
        holder.dataBinding2.tvName.text = entity.userName



        //设置点击事件
        holder.dataBinding2.tvFocus.setOnClickListener{
            itemClickListener?.onItemClick(it,position)
            holder.dataBinding2.tvFocus.text = "已关注"
            holder.dataBinding2.tvFocus.isEnabled = false
        }


    }


}